import auth from '@/api/auth_create.js'

const state = {
    auth_tree: undefined,
    is_auth_detail_show: false,
    auth_detail: undefined
}

const getters = {
    auth_tree: state => state.auth_tree,
    is_auth_detail_show: state => state.is_auth_detail_show,
    auth_detail: state => state.auth_detail
}

const actions = {
    getAuthTree({commit}) {
        auth.getAuthTree().then(res => {
            commit('GET_AUTH_TREE', res);
        })
    },
    changeIsAuthDetailShow({
        commit
    }, params) {
        if (params.show) {
            auth.authDetail({params: {
                authId: params.id
            }}).then(res => {
                commit('CHANGE_IS_AUTH_DETAIL_SHOW', true)
                commit('CHANGE_AUTH_DETAIL', res)
            })
        } else {
            commit('CHANGE_IS_AUTH_DETAIL_SHOW', false)
        }
    }
}

const mutations = {
    GET_AUTH_TREE(state, data) {
        state.auth_tree = data;
    },
    CHANGE_IS_AUTH_DETAIL_SHOW(state, data) {
        state.is_auth_detail_show = data;
    },
    CHANGE_AUTH_DETAIL(state, data) {
        state.auth_detail = data;
    }
}

export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations
}
